# encoding: utf-8
class RegistrationsController < Devise::RegistrationsController
  #layout 'signin' 
  
  before_filter :configure_permitted_parameters, :only => [:create]
  after_filter :signed_up, :only => :create
  
  protected
  
  def signed_up
    # check the membertype and set max_projects
    case @user.member_type
    when "basic"
      @user.max_projects = 2
    when "pro"
      @user.max_projects = 5
    when "premium"
      @user.max_projects = 10
    else 
      @user.max_projects = 2
    end  
    @user.save 
     
  end
  
  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :email, :password) }
  end
  
  private
    
  def sign_up_params
      params.require(:user).permit(:username, :email, :password, :password_confirmation, :name, :member_type)
  end
  
  def account_update_params
    params.require(:user).permit(:username, :email, :password, :password_confirmation, :current_password, :name, :member_type)
  end
    
end